import { _decorator, Component, Node } from 'cc';
import LeanDynamicScrollView from '../../../../scripts/libs/utils/ScrollView/LeanDynamicScrollView';
import { taskm } from '../../../../scripts/managers/TaskManager';
import { SmartNodePool } from '../../../../scripts/libs/utils/SmartNodePool';
import { Prefab } from 'cc';
import { TaskItem } from './TaskItem';
import { EventTarget } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('DailyTaskScrollView')
export class DailyTaskScrollView extends LeanDynamicScrollView {

    eventTarget: EventTarget = null;

    getDataCount(): number {
        return taskm.taskDailyList.length;
    }

    itemPool = new SmartNodePool();

    @property(Prefab)
    itemPrefab: Prefab = null;

    willBind(): void {
        this.itemPool.setPrefab(this.itemPrefab);
        this.itemPool.prepare(4);
    }

    getItemNode(): Node {
        return this.itemPool.getNode();
    }

    putItemNode(node: Node): void {
        this.itemPool.putNode(node);
    }

    refreshRow(idx) {
        let itemNode = this.currentItems[idx];
        if (itemNode != null) {
            let taskItem = itemNode.getComponent(TaskItem);
            taskItem.eventTarget = this.eventTarget;
            taskItem.taskId.value = taskm.taskDailyList[idx].taskId;
        }
    }

}

